﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.classesBasicas.jogo;
using Biblioteca.fachada;

namespace Desktop.views.cruds.crudsJogo.crudReserva
{
    public partial class AlterarRemoverReserva : Form
    {
        private MenuReserva menuReserva;
        private Reserva reserva;
        private Fachada fachada = new Fachada();
        
        
        public AlterarRemoverReserva(MenuReserva menuReserva, Reserva reserva)
        {
            this.menuReserva = menuReserva;
            this.reserva = reserva;

            menuReserva.Hide();
            
            InitializeComponent();

            if (reserva.Campo.Id == "REMOVIDO")
            {
                reserva.Campo.Tamanho = "REMOVIDO";
                reserva.Campo.Tipo = "REMOVIDO";
                    
            }
            else 
            {
                this.reserva.Campo = fachada.consultarPorIdCampo(reserva.Campo.Id);
            }
            
            inicializaTextsBoxs();
        }

        private void buttonAlterar_Click(object sender, EventArgs e)
        {
            try{
            this.reserva = alteraTextsBoxs();    

            fachada.alterarReserva(reserva);

            menuReserva.carregarGridViewReserva();
            menuReserva.Show();
            this.Dispose();
            MessageBox.Show("Alterado com sucesso");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
       }



        private void buttonRemover_Click(object sender, EventArgs e)
        {
            try
            {
                fachada.removerReserva(this.reserva);

                menuReserva.carregarGridViewReserva();
                menuReserva.Show();
                this.Dispose();
                MessageBox.Show("Removido com sucesso");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void buttonCancelar_Click(object sender, EventArgs e)
        {
            menuReserva.Show();
            this.Dispose();
        }

        private void AlterarRemoverReserva_FormClosed(object sender, FormClosedEventArgs e)
        {
            menuReserva.Show();
            this.Dispose();
        }
        
        
        private void maskedTextBoxHorario_MouseClick(object sender, MouseEventArgs e)
        {
            this.maskedTextBoxHorario.SelectionStart = 0;
        }

        private void maskedTextBoxData_MouseClick(object sender, MouseEventArgs e)
        {
            this.maskedTextBoxData.SelectionStart = 0;
        }


        private void inicializaTextsBoxs()
        {
            this.labelIdValor.Text = this.reserva.Id;
            this.maskedTextBoxHorario.Text = this.reserva.Horario;
            this.maskedTextBoxData.Text = this.reserva.Data;
            this.textBoxDuracao.Text = this.reserva.Duracao;
            this.textBoxNdeJogadores.Text = this.reserva.QuantidadeJogadores;
            this.labelIdCampoValor.Text = this.reserva.Campo.Id;
            this.labelTamanhoCampoValor.Text = this.reserva.Campo.Tamanho;
            this.labelTipoCampoValor.Text = this.reserva.Campo.Tipo;
        }

        private Reserva alteraTextsBoxs()
        {
           
            this.reserva.Id = this.labelIdValor.Text;
            this.reserva.Horario = this.maskedTextBoxHorario.Text;
            this.reserva.Data = this.maskedTextBoxData.Text;
            this.reserva.Duracao = this.textBoxDuracao.Text;
            this.reserva.QuantidadeJogadores = this.textBoxNdeJogadores.Text;
            
            return reserva;
        }
        
        //Validação individual
        public void validacaoTextBox()
        {
            //if (textBoxNome.Text == "")
            //{
            //    textBoxNome.Focus();

            //    MessageBox.Show("Por favor, informar o nome do cliente:", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            //}
            //else if (maskedTextBoxRg.Text =="") 
            //{
            //    maskedTextBoxRg.Focus();

            //    MessageBox.Show("Tem certeza que quer cadastrar cliente sem Rg?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

            //    //if MessageBoxButtons.YesNo == true 

            //}            
        }



        //Metódo cor entrada TextBox
        private void CorEntrada(TextBox tb)
        {
            tb.BackColor = Color.LightBlue;
        }
        //Metódo cor saída TextBox
        private void CorSaida(TextBox tb)
        {
            tb.BackColor = Color.White;
        }


        //Metódo cor entrada MaskedTextBox
        private void CorEntrada(MaskedTextBox tb)
        {
            tb.BackColor = Color.LightBlue;
        }
        //Metódo cor saída MaskedTextBox
        private void CorSaida(MaskedTextBox tb)
        {
            tb.BackColor = Color.White;
        }


        //Evento TextBox Enter
        private void textBoxDuracao_Enter(object sender, EventArgs e)
        {
            CorEntrada((TextBox)sender);
        }
        //Evento TextBox Leave
        private void textBoxDuracao_Leave(object sender, EventArgs e)
        {
            CorSaida((TextBox)sender);
        }


        //Evento MaskedTextBox Enter
        private void maskedTextBoxHorario_Enter(object sender, EventArgs e)
        {
            CorEntrada((MaskedTextBox)sender);
        }
        //Evento MaskedTextBox Leave
        private void maskedTextBoxHorario_Leave(object sender, EventArgs e)
        {
            CorSaida((MaskedTextBox)sender);
        }
        
    }
}
